home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gnome2-desktop / examples / gnomeprint / example_05.py < prev    next >
Encoding:
Python Source  |  2009-03-14  |  1.9 KB  |  80 lines

  1. #! /usr/bin/env python
  2.  
  3. # *  example_05.c: sample gnome-print code
  4. # *
  5. # *  This program is free software; you can redistribute it and/or
  6. # *  modify it under the terms of the GNU Library General Public License
  7. # *  as published by the Free Software Foundation; either version 2 of
  8. # *  the License, or (at your option) any later version.
  9. # *
  10. # *  This program is distributed in the hope that it will be useful,
  11. # *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # *  GNU Library General Public License for more details.
  14. # *
  15. # *  You should have received a copy of the GNU Library General Public
  16. # *  License along with this program; if not, write to the Free Software
  17. # *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. # *
  19. # *  Authors:
  20. # *    Chema Celorio <chema@ximian.com>
  21. #    Python conversion:
  22. #      Gustavo J. A. M. Carneiro <gustavo@users.sf.net>
  23. # *
  24. # *  Copyright (C) 2002 Ximian Inc. and authors
  25. # *
  26.  
  27. #/*
  28. # * See README
  29. # */
  30.  
  31. import pygtk; pygtk.require("2.0")
  32. import gnomeprint
  33. import warnings
  34.  
  35. def my_draw(gpc):
  36.     gpc.beginpage("1")
  37.  
  38.     gpc.moveto(100, 100)
  39.     gpc.lineto(200, 200)
  40.     gpc.stroke()
  41.     
  42.     gpc.showpage()
  43.  
  44.  
  45. def my_set_names(job):
  46.  
  47.     config = job.get_config()
  48.  
  49.     # Set the printer
  50.     config.set("Printer", "GENERIC")
  51.     printer = config.get("Printer")
  52.     if printer != "GENERIC":
  53.     warnings.warn("Could not set printer to GENERIC Postscript")
  54.     return
  55.     
  56.     job.print_to_file("output_05.ps")
  57.     config.set(gnomeprint.KEY_DOCUMENT_NAME, "Sample gnome-print document")
  58.  
  59.  
  60. def my_dump_orientation(job):
  61.     config = job.get_config()
  62.  
  63.     orientation = config.get(gnomeprint.KEY_PAGE_ORIENTATION)
  64.     print "Orientation is:", orientation
  65.  
  66. def my_print():
  67.     job = gnomeprint.Job(gnomeprint.config_default())
  68.     gpc = job.get_context()
  69.  
  70.     my_set_names(job)
  71.     my_dump_orientation(job)
  72.     
  73.     my_draw(gpc)
  74.  
  75.     job.close()
  76.     job.print_()
  77.  
  78. my_print()
  79. print "Done..."
  80.